from flask import request
from flask_wtf import FlaskForm
from flask_wtf.file import FileAllowed, FileRequired
from wtforms import StringField,SubmitField,FileField
from wtforms.fields.choices import SelectField
from wtforms.validators import DataRequired

from core.blueprints import IMG_ALLOWED_EXTENSIONS, IMG_ALLOWED_MESSAGE, prove_role

class PersonalForm(FlaskForm):
    img = FileField('选择文件', validators=[
        FileAllowed(IMG_ALLOWED_EXTENSIONS, IMG_ALLOWED_MESSAGE)
    ])

    text = StringField('请输入文字')
    submit = SubmitField('上传')

class ProveForm(FlaskForm):
    img = FileField('选择文件', validators=[
        FileRequired(),
        FileAllowed(IMG_ALLOWED_EXTENSIONS,IMG_ALLOWED_MESSAGE)
    ])
    role = SelectField('选择一个角色', choices=[('', '请选择')] + prove_role(),
                       validators=[DataRequired(message='必须选择一个角色')])
    submit = SubmitField('上传')

def is_personal(form:PersonalForm):
    return form.validate_on_submit() and 'submit1' in request.form

def is_prove(form:ProveForm):
    return form.validate_on_submit() and 'submit2' in request.form

def submit_personal(form:PersonalForm,uid):
    if is_personal(form):
        return False

def submit_prove(form:ProveForm,uid):
    if is_prove(form):
        return False

